# -*- coding: utf-8 -*-
# @Time    : 2024/1/2  22:10
# @Author  : zhanghao
# @FileName: RuleConfig.py
# @Software: PyCharm
"""
    Description:
        
"""
from domain.rule import Rule
from domain.match_config import MatchConfig
from config.logger import Logger


class RuleConfig:
    logger = Logger.get()
    version = ''
    name = ''
    rules: list[Rule] = []

    def __int__(self):
        self.name = ''
        self.version = ''

    def configRules(self, match_config: MatchConfig):
        self.version = match_config.version
        self.name = match_config.name

        new_rules = []
        for match_rule in match_config.rules:
            rule = Rule(match_rule.type, match_rule.keyword, match_rule.ret_file_name,
                        match_rule.classify_id, match_rule.grab_content)
            new_rules.append(rule)

        if len(new_rules) > 0:
            self.rules = new_rules
        self.logger.info('规则初始化成功')

    def versionCompare(self, version):
        if version and float(version) > float(self.version):
            return True
        else:
            return False
